#include <iostream>
#include <string>

#define int long long
#define endl '\n'

const int N = 5e5 + 10;

using namespace std;

int ac1[N];
int ans = 0;

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int k;
	cin >> k;

	string s;
	cin >> s;

	char a, b;
	cin >> a >> b;

	int i = 0;
	int j = 0;
	
	for (i = 0; i < s.size(); i++)
	{
		if (s[i] == a)
		{
			ac1[j] = i;
			j++;
		}
		if (s[i] == b)
		{
			if (i + 1 - k < 0 || j == 0)
				continue;

			int l = 0, r = j - 1;
			while (l < r)
			{
				int mid = (l + r + 1) >> 1;
				if (ac1[mid] <= (i + 1 - k))
					l = mid;
				else
					r = mid - 1;
			}

			if (ac1[l] <= i + 1 - k)
				ans += (l + 1);
		}
	}
	cout << ans << endl;

	return 0;
}